package com.bhs.sansonglogistics.ui.mine;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.widget.TextView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseActivity;
import com.bhs.sansonglogistics.bean.CommonProblemDetailBean;
import com.bhs.sansonglogistics.net.NetCallBack;
import com.bhs.sansonglogistics.utils.ToastUtil;
import com.google.gson.Gson;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 常见问题详情
 */
public class CommonProblemDetailActivity extends BaseActivity implements NetCallBack {


    private TextView mTvContent;
    private int id;
    private String content;

    @Override
    public int initLayout() {
        return R.layout.activity_common_problem_detail;
    }

    @Override
    public void initView() {
        content =getIntent().getStringExtra("content");
        id = getIntent().getIntExtra("id", 0);
        TextView mTvTitle = findViewById(R.id.tv_title);
        mTvTitle.setText(getIntent().getStringExtra("title"));
        mTvContent = findViewById(R.id.tv_content);
    }

    @Override
    public void initData() {
        if (id > 0) {
            loadingPopupShow();
            networkRequest(netApi.get_question_info(id, "logistics"), this);
        }
        if(!TextUtils.isEmpty(content)){
            mTvContent.setText(Html.fromHtml(content));
        }
    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {
        CommonProblemDetailBean bean = new Gson().fromJson(json, CommonProblemDetailBean.class);
        loadingPopupDismiss();
        if (bean.isStatus()) {
            mTvContent.setText(Html.fromHtml(bean.getData().getContent()));
        } else {
            ToastUtil.show(bean.getMsg());
        }
    }

    @Override
    public void onFailure(int requestCode) {

    }
}